<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
    <title>Leon Sans - WebGL Basic PIXI</title>

    <style>
        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden;
            outline: 0;
            margin: 0;
            padding: 0;
            cursor: move;
        }
    </style>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.0.4/pixi.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.js"></script>
</head>

<body>
    <script src="../dist/leon.js"></script>
    <script src="js/util.js"></script>
    <script>
        let graphics;
        let leon, controll;

        function init() {
            generatePixi(0x000000);

            graphics = new PIXI.Graphics();
            stage.addChild(graphics);

            controll = {
                color: {},
                align: {},
                drawing: () => {
                    leon.updateDrawingPaths();

                    let i, total = leon.drawing.length;
                    for (i = 0; i < total; i++) {
                        TweenMax.killTweensOf(leon.drawing[i]);
                        TweenMax.fromTo(leon.drawing[i], 1.6, {
                            value: 0
                        }, {
                            delay: i * 0.05,
                            value: 1,
                            ease: Power4.easeOut
                        });
                    }
                },
            };

            leon = new LeonSans({
                text: 'The quick brown\nfox jumps over\nthe lazy dog',
                color: [0xffffff],
                size: getSize(120),
                weight: 300
            });

            const gui = new dat.GUI();
            gui.add(leon, 'text');
            gui.add(leon, 'size', 10, 2000);
            gui.add(leon, 'weight', 1, 900);
            gui.add(leon, 'tracking', -3, 10);
            gui.add(leon, 'leading', -8, 10);
            const alignControll = gui.add(controll, 'align', [ 'left', 'center', 'right'] );
            gui.add(leon, 'maxWidth', 0, 2000);
            gui.add(leon, 'breakWord');
            gui.add(controll, 'drawing');
            const colorControll = gui.add(controll, 'color', [ 'black', 'white', 'yellow' , 'mixed'] );

            alignControll.onChange((value) => {
                leon.align = value;
            });
            alignControll.setValue('left');

            colorControll.onChange((value) => {
                if (value == 'black') {
                    renderer.backgroundColor = 0xf0f0f0;
                    leon.color = [0x342f2e];
                } else if (value == 'white') {
                    renderer.backgroundColor = 0x000000;
                    leon.color = [0xffffff];
                } else if (value == 'yellow') {
                    renderer.backgroundColor = 0x57c4e2;
                    leon.color = [0xffd93c];
                } else if (value == 'mixed') {
                    document.body.style.backgroundColor = '#ffffff';
                    leon.color = [0xff5892, 0xbc92f, 0xffd93c, 0xc0008b];
                }
            });
            colorControll.setValue('white');

            requestAnimationFrame(animate);
        }

        function animate(t) {
            requestAnimationFrame(animate);

            const x = (sw - leon.rect.w) / 2;
            const y = (sh - leon.rect.h) / 2;
            leon.position(x + moveX, y + moveY);

            graphics.clear();
            leon.drawPixi(graphics);

            renderer.render(stage);
        }

        window.onload = () => {
            init();
        };
    </script>
</body>

</html>